<?php
   require_once('framework/msc-load.php');
   require_once('framework/global-session-handler.php');
   require_once('framework/msc-functions.php');
   $hotel = getHotelDetails($_GET['id']);
   $checkstate = false;
   
   if(isset($_GET['check']) && $_GET['check'] == 1):
   
       $rooms = getRoomTypeIDs($_GET['id']);
       $roomIds = '';        
   
       if($rooms):
           foreach($rooms as $room):
               if($roomIds == '')
                  $roomIds = '('. $room['id'];
               else
                   $roomIds .= ','.$room['id'];
           endforeach;
           $roomIds .= ')';
       endif;
   
       if(isset($_GET['start'])){
           $checkin = $_GET['start'];
           $dateFormat = explode('/',$checkin);
           $checkin = $dateFormat[2].'-'.$dateFormat[1].'-'.$dateFormat[0];
       }
   
       if(isset($_GET['end'])){
           $checkout = $_GET['end'];
           $dateFormat = explode('/',$checkout);
           $checkout = $dateFormat[2].'-'.$dateFormat[1].'-'.$dateFormat[0];
       }
   
       if(isset($_GET['guests'])){
          $guests = $_GET['guests'];
       }
   
       $query = 'SELECT ID, Guests FROM ROOM_TYPES WHERE `Guests` >= '.$guests. ' AND ID IN' . $roomIds ;
       $result = $db->query($query);
       $available_rooms = array();
       if($result):
           while ($row = $result->fetch_assoc()):
               $query = 'SELECT COUNT(*) FROM AVAILABILITY WHERE `ID_Type` = '.$row['ID'].' AND `Reservation_Number` >= '.$row['Guests'].' AND Date BETWEEN "'.$checkin.'" AND "'.$checkout.'"';
               $result2 = $db->query($query);
               $row2 = $result2->fetch_row();
               if($row2[0] == 0)
                   array_push($available_rooms,$row['ID']);
           endwhile;
       endif;
   
   else:
       $checkstate = true;
       $roomtypes = getRoomTypesList($_GET['id']);
   endif;
   
   ?>
<!DOCTYPE HTML>
<html>
   <head>
      <title>MSC Hotels</title>
      <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
      <meta name="keywords" content="" />
      <meta name="description" content="">
      <meta name="author" content="MSC Team">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <!-- GOOGLE FONTS -->
      <link href='http://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700' rel='stylesheet' type='text/css'>
      <link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,600' rel='stylesheet' type='text/css'>
      <!-- /GOOGLE FONTS --> 
      <link rel="stylesheet" href="assets/css/bootstrap.css">
      <link rel="stylesheet" href="assets/css/font-awesome.css">
      <link rel="stylesheet" href="assets/css/icomoon.css">
      <link rel="stylesheet" href="assets/css/styles.css">
      <script src="assets/js/modernizr.js"></script>
   </head>
   <body>
      <div class="global-wrap">
         <header id="main-header">
            <div class="header-top">
               <div class="container">
                  <div class="row">
                     <div class="col-md-3">
                        <a class="logo" href="index.php">
                        <img src="assets/img/logo-invert.png" alt="Image Alternative text" title="Image Title" />
                        </a>
                     </div>
                     <div class="col-md-5">
                        <h5 class="text-color">NOTICE: This is an experimental project.</h5>
                     </div>
                     <div class="col-md-4">
                        <div class="top-user-area clearfix">
                           <ul class="top-user-area-list list list-horizontal list-border">
                              <?php if(isRegistered()): ?>
                              <li class="top-user-area-avatar"><a href="user-profile.php">Hi, <?php echo NameShit(); ?></a></li>
                              <li><a href="/logout.php">Log Out</a></li>
                              <?php else: ?>
                              <li class="top-user-area-avatar"><a>Hi, <?php echo getUserName(); ?></a></li>
                              <li><a href="/signup.php">Log In</a></li>
                              <?php endif; ?>
                           </ul>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
            <div class="container">
               <div class="nav">
                  <ul class="slimmenu" id="slimmenu">
                     <li><a href="index.php">Home</a></li>
                     <li><a href="listings.php">Hotels</a></li>
                  </ul>
               </div>
            </div>
         </header>
         <!-- TOP AREA -->
         <div class="container">
            <ul class="breadcrumb">
               <li><a href="index.php">Home</a>
               </li>
               <li><a href="listings.php">Hotels</a>
               </li>
               <li class="active"><a href="#"><?php echo $hotel['hotelName']; ?></a>
               </li>
            </ul>
            <div class="booking-item-details">
               <header class="booking-item-header">
                  <div class="row">
                     <div class="col-md-9">
                        <h2 class="lh1em"><?php echo $hotel['hotelName']; ?></h2>
                        <p class="lh1em text-small"><i class="fa fa-map-marker"></i> <?php echo $hotel['hotelAddress']; ?> , <?php echo $hotel['hotelCity']; ?> , <?php echo $hotel['hotelPostalCode']; ?></p>
                        <ul class="list list-inline text-small">
                           <li><a href="#"><i class="fa fa-envelope"></i> <?php echo $hotel['hotelEmail']; ?></a>
                           </li>
                           <li><a href="#"><i class="fa fa-home"></i> <?php echo $hotel['hotelWebsite']; ?></a>
                           </li>
                           <li><i class="fa fa-phone"></i> <?php echo $hotel['hotelPhone']; ?></li>
                        </ul>
                     </div>
                     <div class="col-md-3">
                        <p class="booking-item-header-price"><small>price from</small>  <span class="text-lg">€<?php echo getsmallerprice($hotel['hotelID']); ?></span>/night</p>
                     </div>
                  </div>
               </header>
               <div class="row">
                  <div class="col-md-6">
                     <div class="tabbable booking-details-tabbable">
                        <ul class="nav nav-tabs" id="myTab">
                           <li class="active"><a href="#tab-1" data-toggle="tab"><i class="fa fa-camera"></i>Photos</a>
                           </li>
                           <li><a href="#google-map-tab" data-toggle="tab"><i class="fa fa-map-marker"></i>On the Map</a>
                           </li>
                        </ul>
                        <div class="tab-content">
                           <div class="tab-pane fade in active" id="tab-1">
                              <!-- START LIGHTBOX GALLERY -->
                              <div class="row row-no-gutter" id="popup-gallery">
                                 <?php 
                                    $photos = unserialize($hotel['hotelPhotos']);
                                    
                                    if($photos):
                                    
                                      		foreach($photos as $photo):
                                    
                                    ?>
                                 <div class="col-md-3">
                                    <a class="hover-img popup-gallery-image" href="<?php echo MEDIA.$photo; ?>" data-effect="mfp-zoom-out">
                                    <img src="<?php echo MEDIA.$photo; ?>" alt="Image Alternative text" title="hotel EDEN MAR suite" /><i class="fa fa-plus round box-icon-small hover-icon i round"></i>
                                    </a>
                                 </div>
                                 <?php
                                    endforeach;
                                    
                                    endif;
                                    
                                    ?>
                              </div>
                              <!-- END LIGHTBOX GALLERY -->
                           </div>
                           <div class="tab-pane fade" id="google-map-tab">
                              <div id="map-canvas" style="width:100%; height:500px;"></div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="col-md-6">
                     <div class="gap"></div>
                     <div class="booking-item-meta">
                        <div class="booking-item-rating">
                           <ul class="icon-list icon-group booking-item-rating-stars">
                              <?php 
                                 $stars = $hotel['hotelStars'];
                                 
                                    for($i=0; $i<$stars; $i++){
                                 
                                    echo '<li><i class="fa fa-star"></i></li>';
                                 
                                 }
                                 
                                 ?>
                           </ul>
                           <span class="booking-item-rating-number"></span>
                        </div>
                     </div>
                     <h4>About the Hotel</h4>
                     <p class="mb30"><?php echo $hotel['hotelDetails']; ?></p>
                     <h4>Hotel Facilities</h4>
                     <ul class="booking-item-features booking-item-features-expand mb30 clearfix">
                        <!-- τυπώνονται τα facilities -->
                        <?php 
                           $facilities = unserialize($hotel['hotelFacilities']);
                           
                               if($facilities){
                           
                                     foreach($facilities as $facilitie ){  
                           
                                       if($facilitie == 'wifi'){
                           
                           	echo ' <li><i class="im im-wi-fi"></i><span class="booking-item-feature-title">Wi-Fi Internet</span></li>';
                           
                                 }elseif($facilitie == 'parking'){	
                           
                               		echo '<li><i class="im im-parking"></i><span class="booking-item-feature-title">Parking</span></li>';
                           
                             	}elseif($facilitie == "pool"){    
                           
                             		echo'<li><i class="im im-pool"></i><span class="booking-item-feature-title">Pool</span></li>';
                           
                             	}elseif($facilitie == "spa"){      
                           
                           echo'<li><i class="im im-spa"></i><span class="booking-item-feature-title">SPA</span></li>';
                           
                             	}elseif($facilitie == "restaurant"){     
                           
                           echo'<li><i class="im im-restaurant"></i><span class="booking-item-feature-title">Restaurant</span></li>';
                           
                             	}elseif($facilitie == "wheelchair"){    
                           
                           echo'<li><i class="im im-wheel-chair"></i><span class="booking-item-feature-title">Wheelchair Access</span></li>';
                           
                             	}elseif($facilitie == "business_center"){  
                           
                           echo'<li><i class="im im-business-person"></i><span class="booking-item-feature-title">Business Center</span></li>';
                           
                           }elseif($facilitie == "children_activities"){     
                           
                           echo'<li><i class="im im-children"></i><span class="booking-item-feature-title">Children Activites</span></li>';             
                           
                           		}elseif($facilitie == "casino"){
                           
                           		echo'<li><i class="im im-casino"></i><span class="booking-item-feature-title">Casino/Gambling</span></li>';
                           
                            		}elseif($facilitie == "bar"){
                           
                           			echo'<li><i class="im im-bar"></i><span class="booking-item-feature-title">Bar/Lounge</span></li>';
                           
                           }
                           
                           }
                           
                             }
                           
                           ?>
                     </ul>
                  </div>
               </div>
               <div class="gap"></div>
               <?php if($available_rooms || $checkstate): ?>
               <h3>Available Rooms</h3>
               <?php else: ?>
               <h3>No Available Rooms. Please search different days</h3>
               <?php endif; ?>
               <div class="row">
                  <div class="col-md-12">
                     <?php if(!$available_rooms || $checkstate): ?>
                     <div class="booking-item-dates-change">
                        <form action="" method="get">
                           <div class="row">
                              <div class="col-md-8">
                                 <div class="input-daterange" data-date-format="dd/mm/yyyy">
                                    <div class="row">
                                       <div class="col-md-6">
                                          <div class="form-group form-group-icon-left"><i class="fa fa-calendar input-icon input-icon-hightlight"></i>
                                             <label>Check in</label>
                                             <input class="form-control" name="start" type="text" />
                                          </div>
                                       </div>
                                       <div class="col-md-6">
                                          <div class="form-group form-group-icon-left"><i class="fa fa-calendar input-icon input-icon-hightlight"></i>
                                             <label>Check out</label>
                                             <input class="form-control" name="end" type="text" />
                                          </div>
                                       </div>
                                    </div>
                                 </div>
                              </div>
                              <div class="col-md-4">
                                 <div class="form-group form-group-select-plus guests-select">
                                    <label>Guests</label>
                                    <div class="btn-group btn-group-select-num" data-toggle="buttons">
                                       <label class="btn btn-primary active">
                                       <input type="radio" name="guests" value="1" checked />1</label>
                                       <label class="btn btn-primary">
                                       <input type="radio" name="guests" value="2" />2</label>
                                       <label class="btn btn-primary">
                                       <input type="radio" name="guests" value="3" />3</label>
                                       <label class="btn btn-primary">
                                       <input type="radio" name="guests" value="4" />4</label>
                                        <label class="btn btn-primary">
                                       <input type="radio" name="guests" value="4+" />4+</label>
                                    </div>
                                    <select class="form-control hidden" name="guests_list">
                                       <option>1</option>
                                       <option>2</option>
                                       <option>3</option>
                                       <option>4</option>
                                       <option selected="selected">5</option>
                                       <option>6</option>
                                       <option>7</option>
                                       <option>8</option>
                                       <option>9</option>
                                       <option>10</option>
                                       <option>11</option>
                                       <option>12</option>
                                       <option>13</option>
                                       <option>14</option>
                                    </select>
                                 </div>
                              </div>
                              <input type="hidden" name="user_id" value="<?php echo getUserID(); ?>" />
                           </div>
                        </form>
                     </div>
                     <div class="gap gap-small"></div>
                     <?php endif; ?>
                     <?php if($available_rooms || $checkstate): ?>
                     <ul class="booking-list">
                        <?php if($checkstate): ?>
                        <?php if($roomtypes): ?>
                        <?php foreach($roomtypes as $roomtype): ?>
                        <li class="room_<?php echo $roomtype['roomID'];?>">
                           <a class="booking-item">
                              <div class="row">
                                 <div class="col-md-3">
                                    <!-- εμφανίζει την πρώτη φωτογραφία -->
                                    <?php 
                                       $photos = unserialize($roomtype['roomPhotos']);
                                       
                                       if($photos):
                                       
                                           $photo = $photos[0];
                                       
                                       endif;
                                       
                                       ?>								
                                    <img src="<?php echo MEDIA.$photo; ?>" alt="Image Alternative text" title="hotel 1" />
                                 </div>
                                 <div class="col-md-6">
                                    <h5 class="booking-item-title"><?php echo $roomtype['roomType']; ?></h5>
                                    <p class="text-small"><?php echo $roomtype['roomDetails'];?></p>
                                    <ul class="booking-item-features booking-item-features-sign clearfix">
                                       <li rel="tooltip" data-placement="top" title="Adults Occupancy"><i class="fa fa-male"></i><span class="booking-item-feature-sign">x <?php echo $roomtype['roomGuests']; ?></span>
                                       </li>
                                       <!-- <li rel="tooltip" data-placement="top" title="Beds"><i class="im im-bed"></i><span class="booking-item-feature-sign">x 2</span>
                                          </li>
                                          
                                          <li rel="tooltip" data-placement="top" title="Room footage (square feet)"><i class="im im-width"></i><span class="booking-item-feature-sign">330</span>
                                          
                                          </li>-->
                                    </ul>
                                    <ul class="booking-item-features booking-item-features-small clearfix">
                                       <li rel="tooltip" data-placement="top" title="Bathtub"><i class="im im-bathtub"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Kitchen"><i class="im im-kitchen"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Soundproof"><i class="im im-soundproof"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Terrace"><i class="im im-terrace"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Washing Machine"><i class="im im-washing-machine"></i>
                                       </li>
                                    </ul>
                                 </div>
                                 <div class="col-md-3"><span class="booking-item-price">€<?php echo $roomtype['roomPrice'];?></span><span>/night</br></span>
                                  <span class="btn btn-primary check-availability" data-room="<?php echo $roomtype['roomID'];?>" >Check & Book</span>
                                  <form method="post" action="booking.php" class="hide book-form">
                                      <input type="hidden" name="hotel_id" value="<?php echo $_GET['id'];?>" />
                                      <input type="hidden" name="room_id" value="<?php echo $roomtype['roomID'];?>" />
                                      <input type="hidden" name="price" value="<?php echo $roomtype['roomPrice'];?>" />
                                      <input type="hidden" name="checkin" value="" />
                                      <input type="hidden" name="checkout" value="" />
                                      <input type="hidden" name="user_id" value="<?php echo getUserID(); ?>" />
                                      <input type="submit" value="Book" class="btn btn-primary" />
                                  </form>
                                 </div>
                              </div>
                           </a>
                        </li>
                        <?php endforeach; ?>
                        <?php endif; ?>
                        <?php else: ?>
                        <?php foreach($available_rooms as $room_id): ?>
                        <?php $roomtype = getRoomByID($room_id);?>
                        <li>
                           <a class="booking-item">
                              <div class="row">
                                 <div class="col-md-3">
                                    <!-- εμφανίζει την πρώτη φωτογραφία -->
                                    <?php 
                                       $photos = unserialize($roomtype['roomPhotos']);
                                       
                                       if($photos):
                                       
                                           $photo = $photos[0];
                                       
                                       endif;
                                       
                                       ?>								
                                    <img src="<?php echo MEDIA.$photo; ?>" alt="Image Alternative text" title="hotel 1" />
                                 </div>
                                 <div class="col-md-6">
                                    <h5 class="booking-item-title"><?php echo $roomtype['roomType']; ?></h5>
                                    <p class="text-small"><?php echo $roomtype['roomDetails'];?></p>
                                    <ul class="booking-item-features booking-item-features-sign clearfix">
                                       <li rel="tooltip" data-placement="top" title="Adults Occupancy"><i class="fa fa-male"></i><span class="booking-item-feature-sign">x <?php echo $roomtype['roomGuests']; ?></span>
                                       </li>
                                       <!-- <li rel="tooltip" data-placement="top" title="Beds"><i class="im im-bed"></i><span class="booking-item-feature-sign">x 2</span>
                                          </li>
                                          
                                          <li rel="tooltip" data-placement="top" title="Room footage (square feet)"><i class="im im-width"></i><span class="booking-item-feature-sign">330</span>
                                          
                                          </li> -->
                                    </ul>
                                    <ul class="booking-item-features booking-item-features-small clearfix">
                                       <li rel="tooltip" data-placement="top" title="Bathtub"><i class="im im-bathtub"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Kitchen"><i class="im im-kitchen"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Soundproof"><i class="im im-soundproof"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Terrace"><i class="im im-terrace"></i>
                                       </li>
                                       <li rel="tooltip" data-placement="top" title="Washing Machine"><i class="im im-washing-machine"></i>
                                       </li>
                                    </ul>
                                 </div>
                                 <div class="col-md-3">
                                     <span class="booking-item-price">€<?php echo $roomtype['roomPrice'];?></span><span>/night</br></span>
                                      <form method="post" action="booking.php" class="book-form">
                                          <input type="hidden" name="hotel_id" value="<?php echo $_GET['id'];?>" />
                                          <input type="hidden" name="room_id" value="<?php echo $room_id; ?>" />
                                          <input type="hidden" name="price" value="<?php echo $roomtype['roomPrice']; ?>" />
                                          <input type="hidden" name="checkin" value="<?php echo $checkin; ?>" />
                                          <input type="hidden" name="checkout" value="<?php echo $checkout; ?>" />
                                          <input type="hidden" name="user_id" value="<?php echo getUserID(); ?>" />
                                          <input type="submit" value="Book" class="btn btn-primary" />
                                      </form>
                                 </div>
                              </div>
                           </a>
                        </li>
                        <?php  endforeach; ?>
                        <?php endif; ?>
                     </ul>
                     <?php endif; ?>        
                  </div>
               </div>
            </div>
         <div class="gap gap-small"></div>
      </div>
      <footer id="main-footer">
         <div class="container">
            <div class="row row-wrap">
               <div class="col-md-3">
                  <a class="logo" href="index.php">
                  <img src="assets/img/logo-invert.png" alt="Image Alternative text" title="Image Title" />
                  </a>
                  <p class="mb20">Booking, reviews and advices on hotels and lots more!</p>
                  <ul class="list list-horizontal list-space">
                     <li>
                        <a class="fa fa-facebook box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                     </li>
                     <li>
                        <a class="fa fa-twitter box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                     </li>
                     <li>
                        <a class="fa fa-google-plus box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                     </li>
                     <li>
                        <a class="fa fa-linkedin box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                     </li>
                     <li>
                        <a class="fa fa-pinterest box-icon-normal round animate-icon-bottom-to-top" href="#"></a>
                     </li>
                  </ul>
               </div>
               <div class="col-md-4">
                  <h4>Have Questions?</h4>
                  <h5><a href="#" class="text-color">al.s.katsaros@gmail.com</a></h5>
                  <h5><a href="#" class="text-color">cskostas@gmail.com</a></h5>
                  <h5><a href="#" class="text-color">g.gravanis@gmail.com</a></h5>
                  <h5><a href="#" class="text-color">grgstoupas@gmail.com</a></h5>
                  <p>24/7 Dedicated Customer Support</p>
               </div>
               <div id="project-details" class="col-md-5">
                  <h4>This is an experimental project</h4>
                  <h5 class="text-color">based on "Software Engineering for Web Applications" course of "Master of Science (MSc) in Web Intelligence"</h5>
                  <a href="http://msc.it.teithe.gr/" target="_blank"><img src="assets/img/logo-swk-final-s.png" alt="" style="width:80%;" /></a>
               </div>
            </div>
         </div>
      </footer>
    <div id="overlay"><div class="table"><div class="cell"><i class="fa fa-circle-o-notch fa-spin"></i></div></div></div>
      <script src="assets/js/jquery.js"></script>
      <script src="assets/js/bootstrap.js"></script>
      <script src="assets/js/slimmenu.js"></script>
      <script src="assets/js/bootstrap-datepicker.js"></script>
      <script src="assets/js/bootstrap-timepicker.js"></script>
      <script src="assets/js/nicescroll.js"></script>
      <script src="assets/js/dropit.js"></script>
      <script src="assets/js/ionrangeslider.js"></script>
      <script src="assets/js/icheck.js"></script>
      <script src="assets/js/fotorama.js"></script>
      <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
      <script src="assets/js/typeahead.js"></script>
      <script src="assets/js/card-payment.js"></script>
      <script src="assets/js/magnific.js"></script>
      <script src="assets/js/owl-carousel.js"></script>
      <script src="assets/js/fitvids.js"></script>
      <script src="assets/js/tweet.js"></script>
      <script src="assets/js/countdown.js"></script>
      <script src="assets/js/gridrotator.js"></script>
      <script src="assets/js/custom.js"></script>
      <script type="text/javascript">
         if ($('#map-canvas').length) {
         
             var map, service;
             jQuery(function($) {
         
                 $(document).ready(function() {
                     var latlng = new google.maps.LatLng(<?php echo $hotel['hotelCoords'] ?>);
                     var myOptions = {         
                         zoom: 16,        
                         center: latlng,       
                         mapTypeId: google.maps.MapTypeId.ROADMAP,       
                         scrollwheel: false      
                     };

                     map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

                     var marker = new google.maps.Marker({        
                         position: latlng,      
                         map: map      
                     });
         
                     marker.setMap(map);

                     $('a[href="#google-map-tab"]').on('shown.bs.tab', function(e) {         
                         google.maps.event.trigger(map, 'resize');         
                         map.setCenter(latlng);         
                     });
                     
                     $('.book-form').submit(function(){
                        $('.login-first').remove();
                        var user_id = $('.booking-item-dates-change input[name=user_id]').val();
                        if(user_id == 0){
                            $('.book-form').append('<span class="login-first"><br/><br/>Please <a href="http://mschotels.com/signup.php">login</a> to continue.</span>');
                            return false;
                        }
                             
                     });
                     
                     $('.check-availability').click(function(){
                         var roomID = $(this).attr('data-room');
                         var checkin = $('.booking-item-dates-change input[name=start]').val();
                         var checkout = $('.booking-item-dates-change input[name=end]').val();
                         var user_id = $('.booking-item-dates-change input[name=user_id]').val();
                         
                         var guests = $('.guests-select input[name=guests]:checked').val();
                         var guest_list = $('.guests-select select[name=guests_list]').val();
                         
                         if(guests == '4+')
                             guests = guest_list;
                         
                         $('#overlay').fadeIn();
                         
                         /*
                             Returned Codes
                             1 -> Available
                             0 -> Not Available
                             -1 -> Cannot accomondate guests
                         */
                         $.ajax({
                            type: "POST",
                            url: "check-availability.php",
                            data: { roomID: roomID, checkin: checkin, checkout: checkout, guests: guests }
                         }).done(function(msg) {
                             if(msg == 1){
                                 var checkinTemp = checkin.split('/');
                                 checkinFormated = checkinTemp[2] + '-' + checkinTemp[1] + '-' + checkinTemp[0];
                                 var checkoutTemp = checkout.split('/');
                                 checkoutFormated = checkoutTemp[2] + '-' + checkoutTemp[1] + '-' + checkoutTemp[0];
                                 
                                 $('li.room_' + roomID + ' .check-availability').hide();
                                 $('li.room_' + roomID + ' form').removeClass('hide');
                                 $('li.room_' + roomID + ' form input[name=checkin]').val(checkinFormated);
                                 $('li.room_' + roomID + ' form input[name=checkout]').val(checkoutFormated);
                                 
                                 $('#overlay').fadeOut();
                                 if(user_id == 0)
                                     $('li.room_' + roomID + ' .booking-item .row > div').eq(2).append('<span class="login-first"><br/>Please <a href="http://mschotels.com/signup.php">login</a> to continue.</span>');
                                 else     
                                     $('li.room_' + roomID + ' form').submit();
                             }
                             else if(msg == 0){
                                 $('li.room_' + roomID + ' .check-availability').text('No Availability');
                             }
                             else if(msg == -1){
                                 $('li.room_' + roomID + ' .check-availability').text('No Capacity');
                             }
                             $('#overlay').fadeOut();
                             return false;
                         });
                         
                     });
                 });
             });
         }
      </script>
      </div>
   </body>
</html>